package com.nuoniu.sibanyun.mapper.crm;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nuoniu.sibanyun.entity.crm.CrmStrategy;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 客户策略（新） Mapper 接口
 * </p>
 *
 * @author baiqiang
 * @since 2020-06-15
 */
@Mapper
@Component
public interface CrmStrategyMapper extends BaseMapper<CrmStrategy> {

    /**
     * 保存客户策略
     * @author 小啊刚
     * @date 2020/6/16
     */
    @Insert("insert into crm_strategy (strategy_name, strategy_code, strategy_val, strategy_type, company_id, company_name, remarks, create_user_id, create_user_name, update_user_id, update_user_name) " +
            "select strategy_name, strategy_code, strategy_val, strategy_type, #{companyId}, #{companyName}, remarks, #{userId}, #{realName}, #{userId}, #{realName} from crm_strategy where company_id = 1")
    void saveAll(Long companyId, String companyName, Long userId, String realName);

    /**
     * 修改策略
     * @author 小啊刚
     * @date 2020/6/17
     */
    @Update("update crm_strategy set strategy_val = #{value} where strategy_code = #{key} and company_id = #{companyId}")
    void updateVal(Integer companyId, String key, String value);

    /**
     * 根据code获取策略
     * @author 小啊刚
     * @date 2020/6/20
     */
    @Select("select * from crm_strategy where strategy_code = #{code} and company_id = #{companyId}")
    CrmStrategy getStrategyByCode(String code, Integer companyId);

    @Update("update crm_strategy set auxiliary_value = #{value} where strategy_code = #{key} and company_id = #{companyId}")
    void updateAuxiliary(Integer companyId, String key, String value);

    @Update("update crm_strategy set user_names = #{value} where strategy_code = #{key} and company_id = #{companyId}")
    void updateUserNems(Integer companyId, String key, String value);
}
